import yunapi from '@/api/yunapi'

const coreModuleObj = {
  state: {
    id: 0,
    songName: '',
    artistName: '',
    lrcLink: '',
    songLink: '',
    paused: false,
    currentTime: 0,
    duration: 0,
    debugTxt: []
  },
  actions: {
    async getInfo ({commit}, id) {
      let data = await yunapi.get(id)
      commit('updateInfo', data)
    }
  },
  mutations: {
    updateInfo (state, payload) {
      state.id = payload.songId
      state.songName = payload.songName
      state.artistName = payload.artistName
      state.lrcLink = payload.lrcLink
      state.songLink = payload.songLink
    },
    flushInfo (state) {
      state.paused = window.player.paused
      state.currentTime = window.player.currentTime
      state.duration = window.player.duration
    },
    debug (state, payload) {
      state.debugTxt = payload
    }
  }
}

export default coreModuleObj
